#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
    int kind1, kind2;
    char number[100];
    char change[20] = { "0123456789ABCDEF" };
    scanf("%d %s %d", &kind1, number, &kind2);
    for (int i = 0; i < strlen(number); i++)
    {
        if (number[i] >= 'a' && number[i] <= 'z')
            number[i] -= 32;
    }
    long target = 0, temp;
    int len = strlen(number);
    for (int i = 0; i < strlen(number); i++)
    {
        for (int j = 0; j < 16; j++)
        {
            if (number[i] == change[j])
            {
                target += j * pow(kind1, len - 1);
                len--;
            }
        }
    }
    char targetnumber[100];
    int len1 = 0;
    if (target == 0)
        printf("0");
    while (target != 0)
    {
        temp = target % kind2;
        targetnumber[len1++] = change[temp];
        target = target / kind2;
    }
    for (int i = len1 - 1; i >= 0; i--)
    {
        printf("%c", targetnumber[i]);
    }
}